package Homework_03_31;

class hero
{
    private String name;
    private int hp;
    private int ATK;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getHp() {
        return hp;
    }

    public void setHp(int health_points) {
        this.hp = health_points;
    }

    public int getATK() {
        return ATK;
    }

    public void setATK(int ATK) {
        this.ATK = ATK;
    }

    public hero(String name, int hp, int ATK) {
        this.name = name;
        this.hp = hp;
        this.ATK = ATK;
    }

    public hero() {
    }

    public void print()
    {
        System.out.println("hero的信息 " + "姓名:" + this.name + "  生命值:" + this.hp + "  攻击力:" + this.ATK);
    }

    public void attach(hero h, int atk)
    {
        h.hp -= atk;
        System.out.println(h.getName() + "受到" + this.name + "的攻击" + " 生命值剩余" + h.hp);
        System.out.println("更新" + h.getName() + "的信息");
        h.print();
    }
}


public class Main3 {
    public static void main(String[] args) {
        hero h1 = new hero("Sun WuKong",100,5);
        hero h2 = new hero("Hou Yi",60,6);
        System.out.println("打印两个英雄的初始信息");
        h1.print();
        h2.print();
        System.out.println("进行回合式战斗");
        int flag = 1;
        System.out.println("-------------------------");
        while(true)
        {
            if(h1.getHp() != 0 && h2.getHp() != 0)
            {
                System.out.println("第" + flag + "回合");
                //attach的第一个参数是被攻击的英雄，第二个参数是攻击方的攻击力
                h1.attach(h2,h1.getATK());
                if(h2.getHp() == 0)
                {
                    System.out.println(h2.getName() + "被" + h1.getName() + "打败了");
                    return;
                }
                h2.attach(h1,h2.getATK());
                if(h1.getHp() == 0)
                {
                    System.out.println(h1.getName() + "被" + h2.getName() + "打败了");
                    return;
                }
                flag++;
                System.out.println("----------------------------");
            }
        }
    }
}
